#include "StuMode.h"
#include <fstream>

Mode::Mode() 
{

}

Mode::Mode(const Mode&)
{

}
	
Mode& Mode::operator = (const Mode&)
{
}

void Mode::removeStudent(int id)
{
	for(vector<Student>::iterator it = stus.begin(); it != stus.end(); it++){
		if(id == it-> getId()){
			stus.erase(it);
			break;
		}
	}
}
Mode* Mode::instance = 0;

Mode* Mode::getInstance()
{
	if(0 == instance)
		instance = new Mode();
	return instance;
}

void Mode::insertStudent(const Student& stu)
{
	stus.push_back(stu);
}


void Mode::display() const
{
	for(vector<Student>::const_iterator it = stus.cbegin(); it != stus.cend(); ++it){
		cout << *it;
	}
}

void Mode::loadStudent(const char* pathName)
{
	ifstream in;
	in.open(pathName, fstream::in);
	if(!in.is_open()){
		cerr << "打开文件失败" << endl;
		return ;
	}
	
	//读取
	Student stu;
	while(in >> stu){
		stus.push_back(stu);
	}
	
	in.close();
}
void Mode::saveStudent(const char* pathName)
{
	ofstream out;
	out.open(pathName, fstream::out);
	if(!out.is_open()){
		cerr << "打开文件失败" << endl;
		return ;
	}
	
	//读取
	for(vector<Student>::iterator it = stus.begin(); it != stus.end(); ++it){
		out << *it;
	}
	
	out.close();
}






